package com.oner365.test.socket.connection;

import java.net.ServerSocket;
import java.net.Socket;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ShortConnectionServer {
  private static final Logger LOGGER = LoggerFactory.getLogger(ShortConnectionServer.class);
  private static final int PORT = 8883;
  private static ServerSocket serverSocket;

  public static void main(String[] args) {
    int count = 1;
    try {
      serverSocket = new ServerSocket(PORT);
      LOGGER.info("服务器已经启动。。。");
      while (true) {
        Socket socket = serverSocket.accept();
        LOGGER.info("共{}次链接", count);
        LOGGER.info("现连接IP地址是:{}" , socket.getInetAddress());
        count++;
        Thread thread = new Thread(new ShortConnectionExecute(socket));
        thread.start();
      }
    } catch (Exception e) {
      LOGGER.error("serverSocket error:",e);
    }
  }

}
